#!/usr/bin/env python
# -*- coding: utf-8 -*-
#


def reverseURL(url):  
    link = filter(None, url.split("://"))
    if len(link) < 2 :
        return url
    link = link[ -1 ]

    hops = filter(None, link.split("/"))  
    hostname = hops[0]
    domain = filter(None, hostname.split(':'))[0]
    domain = domain.split(".")  
    if domain[-1].isdigit() :
        domain = hostname
    else :
        domain.reverse()  
        domain = '.'.join(domain)  
    hops[0] = domain  
    return '/'.join(hops)   
    #### reverseURL()
    

if  __name__ == '__main__' :
    for url in ('http://www.abc.com/index.php','http://www.abc.com:80/index.php','com.abc.www/index.php','http://192.168.0.2/index.php') :
        print   url,'-->',reverseURL( url )

